package com.hibiscusking.basic.controller;

import com.hibiscusking.basic.config.BussinessException;
import com.hibiscusking.basic.dto.EmailVerificationDto;
import com.hibiscusking.basic.dto.PhoneSmsCodeDto;
import com.hibiscusking.basic.dto.PhoneVerificationDto;
import com.hibiscusking.basic.service.RegisterService;
import com.hibiscusking.basic.util.AjaxResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @PostMapping("/phone")
    public AjaxResult phoneRegister(@RequestBody @Valid PhoneSmsCodeDto phoneSmsCodeDto) {
        registerService.phoneRegister(phoneSmsCodeDto);
        return AjaxResult.me().success();
    }
    @PostMapping("/email")
    public AjaxResult emailRegister(@RequestBody @Valid EmailVerificationDto edto) {
        if (StringUtils.isBlank(edto.getEmail())) {
            throw new BussinessException("邮箱不能为空");
        }
        registerService.emailRegister(edto);
        return AjaxResult.me().success();
    }
}
